package cn.gz.demo.ui.guide;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.databinding.DataBindingUtil;

import cn.gz.demo.R;
import cn.gz.demo.databinding.GuideCommonBinding;
import cn.gz.demo.ui.base.BaseActivity;
import cn.gz.demo.ui.guide.Component.LottieComponent;
import cn.gz.demo.ui.guide.Component.MutiComponent;
import cn.gz.demo.ui.guide.Component.SimpleComponent;
import cn.gz.demo.view.guide.Component;
import cn.gz.demo.view.guide.Guide;
import cn.gz.demo.view.guide.GuideBuilder;

/**
 * Created by Liuyz on 2019/8/28.
 * <p>
 * github地址: https://github.com/binIoter/GuideView
 */
public class GuideCommonActivity extends BaseActivity {
    private GuideCommonBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_guide_common_activity);
        initView();
        initListener();
    }


    private void initView() {
        binding.headerImgbtn.post(new Runnable() {
            @Override
            public void run() {
                showGuideView();
            }
        });
    }

    private void initListener() {
        binding.headerImgbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(GuideCommonActivity.this, "show", Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void showGuideView() {
        GuideBuilder builder = new GuideBuilder();
        builder.setTargetView(binding.headerImgbtn)
                .setAlpha(150)
                .setHighTargetCorner(20)
                .setHighTargetPadding(10);
        builder.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
            @Override
            public void onShown() {
            }

            @Override
            public void onDismiss() {
                showGuideView2();
            }
        });

        builder.addComponent(new SimpleComponent());
        Guide guide = builder.createGuide();
        guide.show(GuideCommonActivity.this);
    }

    public void showGuideView2() {
        final GuideBuilder builder1 = new GuideBuilder();
        builder1.setTargetView(binding.llNearby)
                .setAlpha(150)
                .setHighTargetGraphStyle(Component.CIRCLE);
        builder1.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
            @Override
            public void onShown() {
            }

            @Override
            public void onDismiss() {
                showGuideView3();
            }
        });

        builder1.addComponent(new MutiComponent());
        Guide guide = builder1.createGuide();
        guide.show(GuideCommonActivity.this);
    }

    @SuppressLint("ResourceType")
    public void showGuideView3() {
        final GuideBuilder builder1 = new GuideBuilder();
        builder1.setTargetView(binding.llVideo)
                .setAlpha(150)
                .setHighTargetCorner(20)
                .setHighTargetPadding(10)
                .setExitAnimationId(R.anim.slide_out_to_bottom);
        builder1.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
            @Override
            public void onShown() {
            }

            @Override
            public void onDismiss() {
            }
        });

        builder1.addComponent(new LottieComponent());
        Guide guide = builder1.createGuide();
        guide.setShouldCheckLocInWindow(false);
        guide.show(GuideCommonActivity.this);
    }
}
